#include"head.h"

pthread_mutex_t mysql_lock = PTHREAD_MUTEX_INITIALIZER; 

bool mysql_connect(MYSQL** conn, char* user, char* password, char* db_name){


    pthread_mutex_lock(&mysql_lock);

    *conn = mysql_init(NULL);
    if(*conn == NULL){
        pthread_mutex_unlock(&mysql_lock);
        perror("mysql_init");
        return false;
    }

    *conn = mysql_real_connect(*conn, "localhost", user, password, db_name, 0, NULL, 0);
    if(*conn == NULL){
        pthread_mutex_unlock(&mysql_lock);
        mysql_close(*conn);
        perror("mysql_real_connect");
        return false;
    }


    pthread_mutex_unlock(&mysql_lock);


    return true;
}
